import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
import $ from 'jquery';
import MFS from '@/common/mfs_oauth.js';



export default {
  name: 'site',
  components: {},
  data () {
    return {
      siteId: '',
      studentId: '',
      spelName: '',
      area: '',
      term: '',
      weekDay: '',
      spelId: '',
      pageNo: 1,
      content: [],
      optionsArea: [],
        propsArea: {
        value: 'value',
        children: 'cities'
      },
      parentCodeArea: '0',
      optionsProvince: [],
      optionsCity: [],
      optionsOrg: [],

      optionsCityAll: [],
      optionsOrgAll: [],

      optionsWeekDay: [],
      selectedOptionsArea: [],
      selectedOptionsCity: [],
      selectedOptionsProvince: [],
      selectedOptionsWeekDay: []
    }
  },
  mounted () {
    MFS.initNav({
      //中间标题
      "title" : "青少年宫",

      //左侧按钮
      "leftButton" : {
        "handler" : "MFS.goBack"//回调函数名
      },

      //右侧按钮
      "rightButton" : {
        "text" : "",//若标题右侧需要展示分享等类似链接按钮，需传值
        "handler" : "MFS.navRightCallback2"//回调函数名
      }
    });
    //MFS.showNav()
    this.init()
  },
  methods: {
    changeProvinceSelected () {
      var _this = this
      _this.optionsCity = []
      for(var i = 0;i < _this.optionsCityAll.length;i++) {
        var city = _this.optionsCityAll[i];
        if(city.parentId == _this.selectedOptionsProvince) {
          _this.optionsCity.push(city)
        }
      }
    },
    changeCitySelected () {
      var _this = this
      _this.optionsOrg = []
      for(var i = 0;i < _this.optionsOrgAll.length;i++) {
        var org = _this.optionsOrgAll[i];
        if(org.parentId == _this.selectedOptionsCity) {
          _this.optionsOrg.push(org)
        }
      }
    },
    init () {
      // 专业 改成了  区域
      var _this = this
      http.post(CONSTANT.ORGLIST, {subSystem:2700,isDel:0}, (res) => {
        let data = res.data
        for (var i = 0;i < data.length;i++) {
          var item = data[i];
          var termFirst = {}
          termFirst.label = item.name
          termFirst.value = item.id
          _this.optionsProvince.push(termFirst)//省
          var citys = item.childArea;
          for (var j = 0;j < citys.length;j++) {
            var city = citys[j];
            var termFirstCity = {}
            termFirstCity.label = city.name
            termFirstCity.value = city.id
            termFirstCity.parentId = item.id
            _this.optionsCityAll.push(termFirstCity)//市
            var orgs = city.orgList;
            for (var k = 0;k < orgs.length;k++) {
              var org = orgs[k];
              var termFirstOrg = {}
              termFirstOrg.label = org.name
              termFirstOrg.value = org.id
              termFirstOrg.parentId = city.id
              _this.optionsOrgAll.push(termFirstOrg)//宫
            }
          }
        }
    })
    },
    goCourseDetails (id) {
      sessionStorage.setItem('siteId',id)
      this.setting(id)
    },
    setting(siteId) {
      http.post(CONSTANT.SETTING, {
        orgId: siteId
      }, (res2) => {
        let setting = res2.data.initData.setting
        window.sessionStorage.setItem('setId', setting.id)
      window.sessionStorage.setItem('isStudBack', setting.isStudBack)
      window.sessionStorage.setItem('wechatFees', setting.wechatFees)
      window.sessionStorage.setItem('nxFees', setting.nxFees)
      window.sessionStorage.setItem('isNetApply', setting.isNetApply)
      window.sessionStorage.setItem('isChangeClass', setting.isChangeClass)
      window.sessionStorage.setItem('classNoFlag', setting.classNoFlag)
      window.sessionStorage.setItem('wechatModelId', setting.wechatModelId)
      window.sessionStorage.setItem('idCardNeeds', setting.idCardNeed)
      window.sessionStorage.setItem('beginTime', setting.beginTime)
      window.sessionStorage.setItem('endTime', setting.endTime)
      window.sessionStorage.setItem('randomTime', setting.randomTime)
      let nxFees = setting.nxFees
      if (nxFees == 1) {
        this.$router.push({path: '/Hello'})
      } else {
        alert('该宫暂未开通')
      }
    })
    }
  }
}
